﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TR.AppService.AppService.Wh_Buy_Order_h;
using TR.AppService.Dto;
using TR.AppService.Dto.wh_Buy_Order_hDto;
using TR.Domain.Entity;
using TR.Domain.Entity.BsItemType;
using TR.Domain.Entity.JH;
using TR.EFCore.Repository.Wh_Buy_Order_hRepository;

namespace TR.WebApi.Controllers.Wh_Buy_Order_hControllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class wh_Buy_Order_hController : ControllerBase
    {
        private readonly Iwh_Buy_Order_hAppService wboh;

        public wh_Buy_Order_hController(Iwh_Buy_Order_hAppService wboh)
        {
            this.wboh = wboh;
        }

        //分页查询
        [HttpGet]
        public async Task<DtoFenYe<wh_Buy_Order_h>> FenyeSelectAsync(int mys, int dqy, string name = "")
        {
            return await wboh.FenYeSelect(mys, dqy, name);
        }

        //进货订单编号查询
        [HttpGet]
        public Task<wh_Buy_Order_h> SelectTjAsync(string tj)
        {
            return wboh.OrderBhSelect(tj);
        }

        //进货详情查询

        [HttpGet]
        public Task<List<JHXQ>> JHXQTjSelectAsync(string tj)
        {
            return wboh.JHXQTjSelect(tj);
        }

        //信息新增
        [HttpPost]
        public async Task<bool> InsertAsync([FromBody] JHDataDto jhdd)
        {
            bool jieguo = await wboh.InsertOrder(jhdd.Jhzb, jhdd.Jhmxs);
            if (jieguo)
            {
                return true;
            }else
            {
                return false;

            }
        }

        //信息修改
        [HttpPut]
        public async Task<bool> UpdateAsync([FromBody] JHDataDto1 jhdd)
        {
            bool jieguo = await wboh.UpdateOrder(jhdd.jhzb, jhdd.jhmx);
            if (jieguo)
            {
                return true;
            }
            else
            {
                return false;

            }
        }

        //供应商下拉框
        [HttpGet]
        public async Task<List<bs_Supply>> GYSXlkSelectAsync()
        {
            return await wboh.bs_SubblySelect();
        }

        //供应商信息查询联系人和联系方式
        [HttpGet]
        public async Task<bs_Supply> GYSTjSelect(string tj)
        {
            return await wboh.bs_SupplyTjSelect(tj);
        }

        //货品信息
        [HttpGet]
        public async Task<DtoFenYe<bs_Item>> BsItemSelectAsync(int mys,int dqy,string? tj)
        {
            return await wboh.BsItemSelect(mys, dqy, tj);
        }
    }
}
